package com.wlj.security.core.social;

import org.springframework.social.UserIdSource;
import org.springframework.social.security.SocialAuthenticationFilter;
import org.springframework.social.security.SpringSocialConfigurer;

public class WljSpringSocialConfigurer extends SpringSocialConfigurer {

    private String filterProcessesUrl;

    private UserIdSource userIdSource;

    private SocialAuthenticationFilterPostProcessor socialAuthenticationFilterPostProcessor;

    public WljSpringSocialConfigurer(String filterProcessesUrl){
        this.filterProcessesUrl=filterProcessesUrl;
    }

    /**
     * 覆盖postProcess，修改socialAuthenticationFilter默认拦截的地址
     * @param object
     * @param <T>
     * @return
     */
    @Override
    protected <T> T postProcess(T object) {
        SocialAuthenticationFilter filter= (SocialAuthenticationFilter) super.postProcess(object);
        //配置SocialAuthenticationFilter拦截的url
        filter.setFilterProcessesUrl(filterProcessesUrl);
        if(socialAuthenticationFilterPostProcessor!=null){
            socialAuthenticationFilterPostProcessor.process(filter);
        }
        return (T)filter;
    }

    public SocialAuthenticationFilterPostProcessor getSocialAuthenticationFilterPostProcessor() {
        return socialAuthenticationFilterPostProcessor;
    }

    public void setSocialAuthenticationFilterPostProcessor(SocialAuthenticationFilterPostProcessor socialAuthenticationFilterPostProcessor) {
        this.socialAuthenticationFilterPostProcessor = socialAuthenticationFilterPostProcessor;
    }

    public UserIdSource getUserIdSource() {
        return userIdSource;
    }

    public void setUserIdSource(UserIdSource userIdSource) {
        this.userIdSource = userIdSource;
    }
}
